package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.dao.GoodsMapper;
import com.zhentao.entity.goods.Goods;
import com.zhentao.service.GoodsService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper,Goods> implements GoodsService {
    @Override
    public List<Goods> list(Goods goods) {
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.like(goods.getGoodsName()!=null, "goods_name",goods.getGoodsName());
        wrapper.eq(goods.getCategoryId()!=null,"category_id",goods.getCategoryId());
        wrapper.eq( goods.getStatus()!=null,"status",goods.getStatus());
        if(goods.getStock()!=null){
            switch (goods.getStock()){
                case 1:
                    wrapper.lt("stock",50);
                    break;
                case 2:
                    wrapper.between("stock",50,100);
                    break;
                case 3:
                    wrapper.between("stock",100,500);
                    break;
                case 4:
                    wrapper.gt("stock",500);
                    break;
                default:
                    break;
            }
        }
        List<Goods> goodsList = this.baseMapper.selectList(wrapper);
        return goodsList;
    }
}
